package com.epoch.zuul.auth.controller;

import bean.response.ResponseBean;
import com.epoch.zuul.auth.role.Roles;
import com.epoch.zuul.auth.service.RoleService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author admin
 */
@Slf4j
@RestController
public class RolesController {
    @Autowired
    private RoleService roleService;

    /**
     * 通过id 获取role
     * @param id
     * @return
     */
    @RequiresAuthentication
    @ApiOperation(value = "用户版块")
    @PostMapping("epoch/role/getRoleById")
    public Roles getRoleById(@RequestParam("id") Integer id){
        return roleService.getRoleById(id);
    }

    @RequiresAuthentication
    @ApiOperation(value = "用户版块")
    @GetMapping("epoch/role/getRoleByRoleName")
    public ResponseBean getRoleByRoleName(@RequestParam("roleName") String roleName){
        return roleService.getRoleByRoleName(roleName);
    }

    /**
     * 创建role
     * @param roles
     * @return
     */
    @RequiresAuthentication
    @ApiOperation(value = "用户版块")
    @PostMapping("epoch/role/addRole")
    public ResponseBean addRole(@RequestBody @Valid Roles roles){
        return roleService.addRole(roles);
    }

    /**
     * 删除role
     * @param roleName
     * @return
     */
    @RequiresAuthentication
    @ApiOperation(value = "用户版块")
    @DeleteMapping("/epoch/role/deleteRole")
    public ResponseBean deleteRole(@RequestParam String roleName){
        return roleService.deleteRole(roleName);
    }

    /**
     * 修改角色的相关信息
     * @param roles
     * @return
     */
    @RequiresAuthentication
    @ApiOperation(value = "用户版块")
    @PutMapping("epoch/role/updateRole")
    public ResponseBean updateRole(@RequestBody @Valid Roles roles){
        return roleService.updateRole(roles);
    }

    /**
     * 获取角色列表
     * @param
     * @return
     */
    @RequiresAuthentication
    @ApiOperation(value = "权限版块")
    @GetMapping("epoch/role/getRoleList")
    public ResponseBean getRoleList(){
        return roleService.getRoleList();
    }

}
